<html>

<body>

<?php 
	if( $_COOKIE["username"] ) 
		echo "<br> there is a cookie here";
	else
		echo "<br> there is no username cookie here";
?>
<form action="create_redirect.php" method="post">

<table>
	<tr>
		<td> username: </td>
		<td> <input type="text" name="username" value="<?php if( $_COOKIE["username"] ) echo $_COOKIE["username"]; ?> "/> </td>
	</tr>
	<tr>
		<td> password: </td>
		<td>
			<input type="password" name="password" <?php if( $_COOKIE["password"] ) echo 'value="'.$_COOKIE["password"].'"';  ?> />
		</td>
	</tr>
	<tr>
		<td> verify password: </td>
		<td>
			<input type="password" name="vpassword" <?php if( $_COOKIE["vpassword"] ) echo 'value="'.$_COOKIE["vpassword"].'"'; ?> />
		</td>
	</tr>
	<tr>
		<td> sex: </td>
		<td>
			<input type="radio" name="sex" value="M" <?php if($_COOKIE["gender"] == "M") echo 'checked="true"'; ?> > Male </input> 
			<input type="radio" name="sex" value="F" <?php if($_COOKIE["gender"] == "F") echo 'checked="true"'; ?> > Female </input> 
		</td>
	</tr>
	<tr>
		<td> age: </td>
		<td> <input type="text" name="age" size="2" value="<?php if( $_COOKIE["age"] ) echo $_COOKIE["age"]; ?>"/> </td>
	</tr>
	<tr>
		<td> occupation: </td>
		<td>
			<select name="occupation">
				<option <?php if( $_COOKIE["occupation"] == "engineer" ) echo "selected"; ?> value="engineer"> engineer </option>
				<option <?php if( $_COOKIE["occupation"] == "teacher" ) echo "selected"; ?> value="teacher"> teacher </option>
			</select>
		</td>
	</tr>
	<tr>
		<td> zipcode: </td>
		<td>
			<input type="text" size="5" name="zipcode" <?php if($_COOKIE["zipcode"] ) echo 'value="'.$_COOKIE["zipcode"].'"'; ?>  />
		</td>
	</tr>
 	<tr>
		<td>
			<input type="submit" name="submit" />
		</td>
	</tr>
</table>
</form>

<?php
	$username = trim($_COOKIE["username"]);
	$password = trim($_COOKIE["password"]);
	$vpassword = trim($_COOKIE["vpassword"]);
	$gender = trim($_COOKIE["gender"]);
	$zipcode = trim($_COOKIE["zipcode"]);
	$age = trim($_COOKIE["age"]);
	$occupation = trim($_COOKIE["occupation"]);
	
	if( $password != $vpassword)
		echo("<br> password do not match "); 

	if( $username )
		echo "<br> username: $username";
	else
		echo("<br> no username selected");
	if( $password ) 
		echo "<br> password: $password";
	
	if( $gender )
		echo "<br> gender: $gender ";
	else
		echo("<br> no gender selected");
	
	if( strlen($zipcode) != 5 ) 
		echo("<br>invalid zipcode");
	else
		echo("<br> You must enter a zipcode.");
	
	if( $age ) 
		echo "<br> age: $age";
	else
		echo("<br> You must enter an age.");
	
	if( $occupation )
		echo "<br> occupation: $occupation";
	else
		echo("<br> You must select an occupation");

?>

</body>
</html>
